/**
 *    @file       netprocessthread.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/12/2014 05:47:39 PM
 *
 *    @author     Theophilus (), wangtf418@gmail.com 
 */
#ifndef _SF_NETPROCESSTHREAD_H_
#define _SF_NETPROCESSTHREAD_H_
#include <map>
#include "asynworkthread.h"
#include "sockettask.h"
#include "epoll.h"

class netprocessthread : public asynworkthread
{
public:
	netprocessthread(bf_uint32_t type, bf_uint32_t size, bf_uint32_t index, const comargs *args);
	virtual ~netprocessthread();

public:
	virtual bf_int_t init();
	virtual bf_int_t run();

public:
	virtual bf_int_t process_io_event();
	virtual bf_int_t process_other();
	virtual bf_int_t check_task_timeout();
	inline epoll & get_epoll() {return m_epoll;}

public:
	virtual bf_int_t add_sockettask(sockettask *task);
	virtual bf_int_t del_sockettask(sockettask *task);
	virtual sockettask * find_sockettask(bf_uint64_t taskid);

public:
	void process_epoll_event(bf_epoll_event_t &event);

protected:
	virtual bf_int_t proc_msg(message *msg);
	virtual bf_int_t proc_recv_msg(message *msg);
	virtual bf_int_t proc_send_msg(message *msg);
	virtual bf_int_t proc_send_reqmsg(message *msg);

protected:
	bf_time_t m_check_interval;
	bf_time_t m_last_checktime;
	std::map<bf_uint64_t, sockettask*> m_tasks;
	epoll m_epoll;

};

#endif

